% graphviz.pro

% intended for inclusion in module write_basic_term

:- style_check(-atom).          % allow long atoms


%------------------------------------------------------------------------------
% WRITE BASIC TERM AS GraphViz .dot FORMAT
%------------------------------------------------------------------------------

%   write_basic_term_dot(+Term)
%
%   write graphvis .dot text describing term
%   Term is a basic term represented as a typed prolog term
%
write_basic_term_dot(Term) :-
    format('\
digraph G {
    node [shape=box,style="filled,bold",color=black,fillcolor=cyan];
    { node [label="Term\\n:individual"] root; }

    node [shape=box,style=filled,color=black,fillcolor=cyan];

    rankdir=TB;

'),
    basic_term_dot(Term, root),
    format('\

}
').

basic_term_dot(X::T, ParentId) :-
    X =.. [abstraction|Ps],
    !,
    genid(abstraction, Id),
    memberchk(P::N-Q::M, Ps),
    abstraction_brackets(Q::M, LeftBracket,RightBracket),
    format('~w [shape=hexagon,fillcolor=green,label=":~w\\n~w ... ~w"];\n', [Id, T, LeftBracket,RightBracket]),
    format('~w -> ~w;\n', [ParentId, Id]),
    forall(member(P::N-Q::M,Ps),
        (
        genid(multiplicity, EId),
%        format('~w [shape=ellipse,fillcolor=green,label="a ® b",fontname="symbol"];\n', [EId]),
        format('~w [shape=ellipse,fillcolor=green,label="-->"];\n', [EId]),
        format('~w -> ~w;\n', [Id, EId]),
        basic_term_dot(P::N, EId),
        genid(multiplicity, MId),
        format('~w [label=":~w\\n~w"];\n', [MId, Q::M, Q]),
        format('~w -> ~w;\n', [EId, MId])
        )
    ).

basic_term_dot(X::T, ParentId) :-
    X =.. [tuple|Ps],
    !,
    genid(tuple, Id),
    format('~w [shape=ellipse,fillcolor=yellow,label=":~w\\n( ... )"];\n', [Id, T, T]),
    format('~w -> ~w;\n', [ParentId, Id]),
    forall(member(P,Ps),
        basic_term_dot(P, Id)
    ).

/*
basic_term_dot(X::T, ParentId) :-
    X =.. [::|_],
    genid(constructor, Id),
    format('~w [label=":~w"];\n', [Id, T]),
    format('~w -> ~w;\n', [ParentId, Id]),
    basic_term_dot(X, Id).
*/

basic_term_dot(X::T, ParentId) :-
    X =.. [C|Ps],
    genid(constructor, Id),
    format('~w [label=":~w\\n~w"];\n', [Id, T, C]),
    format('~w -> ~w;\n', [ParentId, Id]),
    forall(member(P,Ps),
        basic_term_dot(P, Id)
    ).



